package middleware

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"time"
)

func Cors() gin.HandlerFunc {
	return cors.New(
		cors.Config{
			// 配置跨域的域名
			//AllowAllOrigins:  true,
			AllowOrigins: []string{"*"}, // 等同于允许所有域名 #AllowAllOrigins:  true
			// 允许请求的方法
			AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
			// 允许的请求头
			AllowHeaders:  []string{"*", "Authorization"},
			ExposeHeaders: []string{"Content-Length", "text/plain", "Authorization", "Content-Type"},
			// 是否发送的是cookie请求
			//AllowCredentials: true,

			// 预请求的持续时间
			MaxAge: 12 * time.Hour,
		},
	)
}
